package com.book.action;

import javax.annotation.Resource;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.book.service.IBookService;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

@Controller("bookAction")
@Scope("prototype")
public class BookAction extends ActionSupport {

	public String getBooktype() {
		return booktype;
	}

	public void setBooktype(String booktype) {
		this.booktype = booktype;
	}

	public String getBookid() {
		return bookid;
	}

	public void setBookid(String bookid) {
		this.bookid = bookid;
	}

	public void setBookService(IBookService bookService) {
		this.bookService = bookService;
	}
	
	public String getAllBook() {
		ActionContext.getContext().getSession().remove("allbook");
		ActionContext.getContext().getSession().put("allbook", bookService.getAllBook());
		return 	SUCCESS;
	}
	
	public String getBookById() {
		ActionContext.getContext().getSession().remove("onebook");
		ActionContext.getContext().getSession().put("onebook", bookService.getBookById(bookid));
		return 	SUCCESS;
	}
	
	public String getBookByType() {
		ActionContext.getContext().getSession().remove("allbook");
		ActionContext.getContext().getSession().put("allbook", bookService.getBookByType(booktype));
		return 	SUCCESS;
	}

	private static final long serialVersionUID = 5648498578549963516L;
	
	@Resource
	private IBookService bookService;
	
	private String bookid;
	private String booktype;
}
